package com.api.shopapi.mapper;

import com.api.shopapi.entity.AskAnswerGroup;
import com.api.shopapi.entity.AskAnswerRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AskAnswerRecordMapper {

    @Insert("insert into ask_answer_record " +
            "(" +
            "AskAnswerRecordCode," +
            "PracticeSiteCode," +
            "Name," +
            "CreateTime,"+
            "GovernmentCode,"+
            "CommandCenterCode,"+
            "AskAnswerNameCode,"+
            "Type,"+
            "UserCode,"+
            "Status"+
            ") " +
            "values " +
            "(" +
            "#{askAnswerRecord.AskAnswerRecordCode}," +
            "#{askAnswerRecord.PracticeSiteCode}," +
            "#{askAnswerRecord.Name}," +
            "#{askAnswerRecord.CreateTime}," +
            "#{askAnswerRecord.GovernmentCode}," +
            "#{askAnswerRecord.CommandCenterCode}," +
            "#{askAnswerRecord.AskAnswerNameCode}," +
            "#{askAnswerRecord.Type}," +
            "#{askAnswerRecord.UserCode}," +
            "#{askAnswerRecord.Status}" +
            ")" )
    int insert(@Param("askAnswerRecord") AskAnswerRecord askAnswerRecord);


    @Delete("delete from ask_answer_record where askAnswerRecordCode=#{askAnswerRecordCode}")
    int delete(@Param("askAnswerRecordCode") String askAnswerRecordCode);


    @Update("update ask_answer_record set " +
            " Status=#{askAnswerRecord.Status}" +
            " where askAnswerRecordCode=#{askAnswerRecord.askAnswerRecordCode}")
    int update(@Param("askAnswerRecord") AskAnswerRecord askAnswerRecord);


    @Select("select * from ask_answer_record where askAnswerRecordCode=#{askAnswerRecordCode} limit 1")
    AskAnswerRecord getByAskAnswerRecordCode(@Param("askAnswerRecordCode") String askAnswerRecordCode);


    @Select("select * from ask_answer_record where askAnswerNameCode=#{askAnswerNameCode} and status=1 limit 1")
    AskAnswerRecord getByAskAnswerNameCode(@Param("askAnswerNameCode") String askAnswerNameCode);

    @Select("select * from ask_answer_record where practiceSiteCode=#{practiceSiteCode}")
    List<AskAnswerRecord> ListByPracticeSiteCode(@Param("practiceSiteCode") String practiceSiteCode);

    @Select("<script>" +
            "select * from ask_answer_record where governmentCode=#{governmentCode}" +
            "<if test =' practiceSiteCode != \"\" '>" +
            " and practiceSiteCode = #{practiceSiteCode} " +
            "</if>" +
            " order by CreateTime desc" +
            "</script>")
    List<AskAnswerRecord> ListByGovernmentCodePracticeSiteCode(@Param("governmentCode") String governmentCode,
                                                               @Param("practiceSiteCode") String practiceSiteCode);


}
